<template>
  <div class="base-layout">
    <!-- 顶部导航栏 -->
    <header class="bg-green-500 text-white p-4 flex items-center">
      <button v-if="!isHomePage" @click="goBack" class="mr-2">
        <ChevronLeft class="w-5 h-5" />
      </button>
      <h1 class="text-lg font-semibold text-center flex-1">
        {{ currentTitle }}
      </h1>
    </header>

    <!-- 主要内容区域 -->
    <main class="min-h-[calc(100vh-60px)]">
      <router-view v-slot="{ Component }">
        <transition name="fade" mode="out-in">
          <component :is="Component" />
        </transition>
      </router-view>
    </main>
  </div>
</template>

<script setup>
import { computed } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import { ChevronLeft } from 'lucide-vue-next';

const router = useRouter();
const route = useRoute();

// 判断是否在首页
const isHomePage = computed(() => {
  return route.path === '/';
});

// 获取当前页面标题
const currentTitle = computed(() => {
  return route.meta.title || '功能菜单';
});

// 返回上一页
const goBack = () => {
  router.back();
};
</script>

<style scoped>
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
</style>